﻿using Microsoft.Extensions.DependencyInjection;
using Modules.Cms.Entitys;
using Modules.Cms.Repositories;
using Modules.Corp.Repositories;
using Modules.Corp;
using PmSoft;
using PmSoft.ApplicationContext;
using Modules.System.Role;

namespace Modules.Cms;

[UseDI(ServiceLifetime.Scoped)]
public class CmsOrderService
{
    private readonly IApplicationContext applicationContext;
    private readonly CmsOrderRepository cmsOrderRepository;

    public CmsOrderService(IApplicationContext applicationContext, CmsOrderRepository cmsOrderRepository)
    {
        this.applicationContext = applicationContext;
        this.cmsOrderRepository = cmsOrderRepository;
    }

    public IPagedList<CmsOrder> GetPages(CmsOrderQuery query, int pageIndex, int pageSize)
    {
        return cmsOrderRepository.GetCmsOrders(query, pageIndex, pageSize);
    }

    public void Create(CmsOrder entity)
    {
        cmsOrderRepository.Insert(entity);
    }

    public void Update(CmsOrder entity)
    {
        cmsOrderRepository.Update(entity);
    }

    public void Delete(int id)
    {
        cmsOrderRepository.DeleteByEntityId(id);
    }

    public CmsOrder? Get(int id)
    {
        return cmsOrderRepository.Get(id);
    }

    public IEnumerable<CmsOrder> GetOrdersByDealerId(int dealerId)
    {
        return cmsOrderRepository.GetOrdersByDealerId(dealerId); 
    }

    public IEnumerable<CmsOrder> GetOrdersByDealerIds(IEnumerable<int> dealerIds) {
        return cmsOrderRepository.GetOrdersByDealerIds(dealerIds);
    }

}
